package com.sense.kukoo.biz_me.model

import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.LoginResultBean
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import okhttp3.RequestBody

class LoginModel:BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName

    override fun onModelCleared() {}

    //source : 用户来源: 0. 内部; 1. facebook; 2. google; 3.apple; 4.twitter; 5. line;
    suspend fun thirdLogin(
        uniqueId: String,
        source: Int,
        avatarUrl: String? = null,
        nickname: String? = null,
    ): ResultBean<LoginResultBean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("uniqueId", uniqueId)
        hashMap.put("source", source)
        avatarUrl?.let {
            hashMap.put("avatarUrl", it)
        }
        nickname?.let {
            hashMap.put("nickname", it)
        }
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .thirdLogin(mRequestBody)
    }

    suspend fun getUserInfo(): ResultBean<UserInfoBean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .getUserInfo("0")
    }
}